<template>
    <view class="page">
        <myNavBar barIcon="back" title="资格认证"></myNavBar>
        <view class="mine-edit">
            <uni-forms ref="form" :modelValue="userInfo" label-position="right" label-width="30%">
                <uni-forms-item label="律师资格证书编号:" name="lowyerCard">
                    <file-upload :maxSize="204800" :onSuccess="onUploadFileSuccess" :onError="onUploadFileFail">
                        <button class="button" type="primary" size="mini">文件上传</button>
                    </file-upload>
                    <!-- <uni-file-picker v-model="imageValue" fileMediatype="image" mode="grid" :limit="1" @select="select"
                        @progress="progress" @success="success" @fail="fail" /> -->
                </uni-forms-item>
            </uni-forms>
            <button type="primary" @click="onSubmit()">提交</button>
        </view>
        <uni-popup ref="message" type="message">
            <uni-popup-message type="error" message="图片大小不能超过 1MB，请重新上传" :duration="3000"></uni-popup-message>
        </uni-popup>
    </view>
</template>

<script>
export default {
    data() {
        return {
            userInfo: {
                lowyerCard: "",
                userId: "",
            },
            fileData: "",
            imageValue: []
        };
    },
    components: {
    },
    methods: {
        // 获取上传状态
        select(e) {
            console.log('选择文件：', e)
            if (e.tempFiles[0].size > 400000) {
                this.$refs.message.open()
            } else {
                this.fileData = e.tempFiles[0].url;
            }
        },
        onUploadFileSuccess(file, res) {
            if (res.code == 200 && file.size < 400000) {
                this.fileData = res.data;
            } else {
                this.$refs.message.open()
            }
        },
        onUploadFileFail(file, res) {
            console.log('file==============>', file);
            console.log('ERROR res==============>', res);
            let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
            msgInfo.loadStatus = 'fail';
        },

        onSubmit() {
            let data = {
                IMAGE_TYPE: "0",
                // IMAGE: 'https://icredit-api-market.oss-cn-hangzhou.aliyuncs.com/%E8%89%BE%E7%A7%91%E7%91%9E%E7%89%B9_%E5%8D%B0%E5%88%B7%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB_%E5%BE%8B%E5%B8%88%E6%89%A7%E4%B8%9A%E8%B5%84%E6%A0%BC%E8%AF%81%E8%AF%86%E5%88%AB/%E5%BE%8B%E5%B8%88%E6%89%A7%E4%B8%9A%E8%B5%84%E6%A0%BC%E8%AF%81.jpg',
                IMAGE: this.fileData
            }
            console.log('data==========》', data);
            uni.request({
                url: `https://lawer.market.alicloudapi.com/ai_market/intelligent_lawyer_qualification_certificate_identification/v1`,
                method: 'POST',
                data: data,
                header: {
                    'Authorization': `APPCODE e1e56ca3f6cf4aec86e5700c465566df`,
                    'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
                },
                success: res => {
                    console.log('认证了', res)
                },
                fail: error => {
                    console.error('请求失败', error)
                }
            })

        },
        realauth(data) {
            this.$httpRequest({
                url: "/newUser/realNameAuthentication",
                method: "PUT",
                data: data,
            }).then(res => {
                console.log('认证了=============================>', res);
                uni.showToast({
                    title: "认证成功",
                    icon: "none",
                });
                setTimeout(() => {
                    uni.navigateBack();
                }, 1000);
            });
        },
    },
    onLoad(options) {
        console.log('options==================>', options);
        this.userInfo.userId = options.id;
    },
};
</script>

<style scoped lang="scss">
.mine-edit {
    margin: 50rpx;

    .head-image {
        width: 200rpx;
        height: 200rpx;
    }
}

.radio {
    margin-right: 20rpx;
}
</style>